//
//  thingdetailsViewController.m
//  UI_HLJ_Frame
//
//  Created by dlios on 15-7-7.
//  Copyright (c) 2015年 毕宏伟. All rights reserved.
//

#import "thingdetailsViewController.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "Web_shoppingViewController.h"

#import "weddingThingModel.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface thingdetailsViewController ()

@property(nonatomic,copy)NSString * Weburl;

// 右上角按钮的属性
@property(nonatomic, assign)BOOL isArchiver;

@property(nonatomic ,retain)NSMutableArray *arr;
@property(nonatomic, retain)NSDictionary *dictemp;


@property(nonatomic, retain)weddingThingModel *wedding;


@end

@implementation thingdetailsViewController
- (void)dealloc
{
    [_Weburl  release];
    [_arr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
  self.title =@"商品详情";
    
    

    
    [self createDATA];

    // Do any additional setup after loading the view.
    
    
    
    
}





-(void)createDATA{
    NSString *url = [NSString stringWithFormat:@"http://hunliji.com/products/%@.json?user_id=981817",self.bid];
    
    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary *dic = responseObject;
        self.dictemp = dic[@"product"];
        UIView  * mainview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

        mainview.backgroundColor = [UIColor colorWithRed:1.000 green:0.559 blue:0.849 alpha:1.000];

        mainview.backgroundColor = [UIColor colorWithRed:1.000 green:0.597 blue:0.707 alpha:1.000];

        [self.view addSubview:mainview];
        
        // 建立imageView
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(15, 10,  WIDTH / 1.09, HEIGHT * 2 / 3)];
        
        // 建立label
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, HEIGHT * 2.1 / 3,WIDTH / 1.8, HEIGHT / 8.3)];
         label.font = [UIFont systemFontOfSize:15];
        label.text = self.dictemp[@"introduce"];
         label.numberOfLines=0;
        [mainview addSubview:label];
        
        // 建立label,显示价钱
        UILabel *labelprice = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH / 2.9,HEIGHT / 1.22, WIDTH / 3, 30)];
//        labelprice.center= CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height-70);
        labelprice.font = [UIFont systemFontOfSize:20];
//        labelprice.backgroundColor = [UIColor yellowColor];
        labelprice.textAlignment=NSTextAlignmentCenter;
        labelprice.text = [NSString stringWithFormat:@"￥%@",self.dictemp[@"price"]];
        labelprice.textColor = [UIColor redColor];
        labelprice.numberOfLines=0;
        [mainview addSubview:labelprice];
        
        // 建立button,立即购买的图
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(WIDTH / 3.8,HEIGHT / 1.14, WIDTH / 2, 60);
//        button.center=CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height-30);
        [button setImage:[UIImage imageNamed:@"shopping _button"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [mainview addSubview: button];
        [image sd_setImageWithURL:[NSURL URLWithString:self.dictemp[@"photo_path"]]];
        [mainview addSubview:image];

        self.Weburl = self.dictemp[@"buy_url"];
 
   
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    
}




-(void)click:(UIButton *)button{
    Web_shoppingViewController *webVC= [[Web_shoppingViewController alloc]init];
    [self.navigationController pushViewController:webVC animated:YES];
    webVC.url = self.Weburl;
    

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
